package cn.cdnsu.base.service.impl;

import cn.cdnsu.base.mapper.BaseMapper;
import cn.cdnsu.base.query.BaseQuery;
import cn.cdnsu.base.service.IBaseService;
import cn.cdnsu.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class IBaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;
    @Override
    public PageInfo<T> queryPage(BaseQuery baseQuery) {
        Integer integer=mapper.countTotal(baseQuery);
        if (integer==0){
            return new PageInfo<>();
        }
        List<T> list=mapper.queryPage(baseQuery);
        return new PageInfo<>(integer,list);

    }

    @Override
    public List<T> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public T selectById(Long id) {
        return mapper.selectById(id);
    }
    @Transactional
    @Override
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete(ids);
    }
    @Transactional
    @Override
    public void update(T t) {
        mapper.update(t);
    }
    @Transactional
    @Override
    public void insert(T t) {
        mapper.insert(t);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

}
